import React, { useReducer } from 'react'
import { Switch, Route, Redirect } from "react-router-dom"
import Index from './pages/Index/Index'
import Login from './pages/Login/Login'
import Register from './pages/Register/Register'
import Detail from './pages/Detail/Detail'
import Coupon from './pages/Coupon/Coupon'
import { initState, reducer } from "./reducer/app"
export const MyContext = React.createContext();
const App = () => {
  const [state, dispatch] = useReducer(reducer, initState);
  return (
    <div className='app'>
      <MyContext.Provider value={ {state,dispatch} }>
        <Switch>
          <Route path={'/detail/:id/:type'} component={Detail}></Route>
          <Route path='/login' component={Login}></Route>
          <Route path={'/index'} component={Index}></Route>
          <Route path={'/register'} component={Register}></Route>
          <Route path={'/coupon'} component={Coupon}></Route>
          <Redirect to='/login'></Redirect>
        </Switch>
      </MyContext.Provider>
    </div>
  )
}
export default App
